package demo;
import org.w3c.dom.*;

import javax.xml.parsers.*;

public class GetElement {
	static final String ARCHIVO = "config.xml";
	Document doc;
	
	void crearDocumento(){
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		DocumentBuilder builder;
		
		try {
			builder = factory.newDocumentBuilder();
			doc = builder.parse(ARCHIVO);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	void leerElemento(){
		Element root = doc.getDocumentElement();
		NodeList prms= root.getElementsByTagName("connectionString");
		for(int i=0; i<prms.getLength(); i++){
			Element prmCon = (Element)prms.item(i);
			System.out.printf("%nid: %s",prmCon.getAttribute("id"));
			System.out.printf("%ndriver: %s",prmCon.getAttribute("driver"));
			System.out.printf("%nurl: %s%n",prmCon.getAttribute("url"));
		}
	}
	
	public static void main(String[] args) {
		GetElement ins = new GetElement();
		ins.crearDocumento();
		ins.leerElemento();
	}

}
